package com.future.mayi.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.LinearLayout;

import com.future.baselib.utils.CommonUtils;
import com.future.baselib.utils.statusbarlibrary.StatusBarUtils;
import com.future.mayi.R;
import com.future.mayi.fragment.RecycleAllOrderFragment;
import com.future.mayi.widget.TitleTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class RecycleAllOrderActivity extends BaseActivity {

    @BindView(R.id.tab_layout)
    TitleTabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.ll_title)
    LinearLayout llTitle;

    private boolean statusBar = false;
    private int statusBarHeight;


    public static void startActivity(Context context, int position) {
        Intent intent = new Intent(context, RecycleAllOrderActivity.class);
        intent.putExtra("position", position);
        context.startActivity(intent);
    }

    @Override
    protected void initLayout() {
        if (StatusBarUtils.setStatusBarTranslucent(getWindow(), true)) {
            statusBar = true;
            statusBarHeight = CommonUtils.getStatusBarHeight(this);
            StatusBarUtils.setStatusBarColor(getWindow(), Color.TRANSPARENT, false);
        }
        setContentView(R.layout.activity_recycle_all_order);
    }

    private List<RecycleAllOrderFragment> fragmentList;
    private List<String> listTitle;

    @Override
    protected void initView() {
        if (statusBar) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) llTitle.getLayoutParams();
            layoutParams.height = CommonUtils.dip2px(mContext, 45) + statusBarHeight;
        }

        listTitle = new ArrayList<>(2);
        fragmentList = new ArrayList<>(2);
        listTitle.add("回收");
        listTitle.add("寄卖");

        RecycleAllOrderFragment recycleFragment = new RecycleAllOrderFragment();
        recycleFragment.setStyle(2);
        RecycleAllOrderFragment soldFragment = new RecycleAllOrderFragment();
        soldFragment.setStyle(1);
        fragmentList.add(recycleFragment);
        fragmentList.add(soldFragment);

        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                if (listTitle != null && listTitle.size() > 0) {
                    return listTitle.get(position);
                }
                return super.getPageTitle(position);
            }
        });
        tabLayout.setupWithViewPager(viewPager);

        if (getIntent() != null) {
            int position = getIntent().getIntExtra("position", 0);
            if (position != 0) viewPager.setCurrentItem(position, true);
        }

    }

    @Override
    protected void initDates() {

    }

    @Override
    protected void initListener() {

    }


    @OnClick(R.id.iv_title_left)
    public void onViewClicked() {
        onBackPressed();
    }


    @Override
    protected void onResume() {
        super.onResume();
        if (fragmentList != null && fragmentList.size() > 0 )
            fragmentList.get(viewPager.getCurrentItem()).refresh();
    }
}
